﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model.Entity;

namespace OnlineNewsEditorial_DaoLibrary.Impl
{
    public class CategoryDao:AbstractDao<Category>
    {
        public override List<Category> getAll()
        {
            try
            {
                var q = from cat in _ctx.Categories
                        select cat;
                return q.ToList<Category>();
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        public Category getById(String catId)
        {
            try
            {
                var q = from cat in _ctx.Categories
                        where cat.catId == catId
                        select cat;
                return q.Single<Category>();
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        public Category getByName(String catName)
        {
            try
            {
                var q = from cat in _ctx.Categories
                        where cat.catName == catName
                        select cat;
                return q.Single<Category>();
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        public List<Category> getByDivision(Division division)
        {
            try
            {
                var q = from cat in _ctx.Categories
                        where cat.Division == division
                        select cat;
                return q.ToList<Category>();
            }
            catch (Exception ex)
            {
                return null;
            }
        }
    }
}
